package com.yanqu.road.entity.activity.snowgarden;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@FieldTypeAnnotation(tableName = "t_u_activity_snow_garden_user")
public class SnowGardenUserData extends DataObject {
    @FieldTypeAnnotation(desc = "活动ID", select = true, update = true)
    private int activityId;

    @FieldTypeAnnotation(desc = "玩家ID", update = true)
    private long userId;

    @FieldTypeAnnotation(desc = "记录阶段")
    private int period;

    @FieldTypeAnnotation(desc = "总步数")
    private int loopNum;

    @FieldTypeAnnotation(desc = "当前位置")
    private int indexNum;

    @FieldTypeAnnotation(desc = "投掷结果合集")
    private List<Integer> resultList = new ArrayList<>();

    @FieldTypeAnnotation(desc = "地图建筑数据")
    private Map<Integer, SnowGardenMapData> indexData = new ConcurrentHashMap<>();  // 地块id，地块信息

    @FieldTypeAnnotation(desc = "外观")
    private int suit;

    @FieldTypeAnnotation(desc = "一阶段积分")
    private int score;
    @FieldTypeAnnotation(desc = "二阶段积分")
    private int secondScore;

    @FieldTypeAnnotation(desc = "外观列表")
    private Map<Integer, SnowGardenSkinData> skinList = new ConcurrentHashMap<>(); // 外观id，外观信息

    @FieldTypeAnnotation(desc = "邀请的门客小人列表")
    private List<Integer> invitedIdList = new ArrayList<>();

    @FieldTypeAnnotation(desc = "尚未结算的事件")
    private List<SnowGardenCombTriggerData> combList = new ArrayList<>();

    @FieldTypeAnnotation(desc = "是否购买战令")
    private boolean isRecharge;

    @FieldTypeAnnotation(desc = "未触发事件保底计数")
    private int guarantee;

    @FieldTypeAnnotation(desc = "初始点数投掷模板")
    private List<Integer> dice = new ArrayList<>();

    @FieldTypeAnnotation(desc = "游客数量")
    private int invitedNum;

    public SnowGardenUserData() {
    }

    public SnowGardenUserData(int activityId, long userId) {
        this.activityId = activityId;
        this.userId = userId;
        setInsertOption();
    }

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        if(this.activityId != activityId) {
            this.activityId = activityId;
            setUpdateOption();
        }
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        if(this.userId != userId) {
            this.userId = userId;
            setUpdateOption();
        }
    }

    public int getPeriod() {
        return period;
    }

    public void setPeriod(int period) {
        if(this.period != period) {
            this.period = period;
            setUpdateOption();
        }
    }

    public int getLoopNum() {
        return loopNum;
    }

    public void setLoopNum(int loopNum) {
        if(this.loopNum != loopNum) {
            this.loopNum = loopNum;
            setUpdateOption();
        }
    }

    public int getIndexNum() {
        return indexNum;
    }

    public void setIndexNum(int indexNum) {
        if(this.indexNum != indexNum) {
            this.indexNum = indexNum;
            setUpdateOption();
        }
    }

    public List<Integer> getResultList() {
        return resultList;
    }

    public void setResultList(List<Integer> resultList) {
        this.resultList = resultList;
    }

    public Map<Integer, SnowGardenMapData> getIndexData() {
        return indexData;
    }

    public void setIndexData(Map<Integer, SnowGardenMapData> indexData) {
        this.indexData = indexData;
    }

    public int getSuit() {
        return suit;
    }

    public void setSuit(int suit) {
        if(this.suit != suit) {
            this.suit = suit;
            setUpdateOption();
        }
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        if(this.score != score) {
            this.score = score;
            setUpdateOption();
        }
    }

    public int getPeriodScore(int period){
        if (period == 1){
            return this.score;
        } else {
            return this.secondScore;
        }
    }

    public void addScore(int period, int addScore) {
        if (period == 1) {
            this.score += addScore;
        } else if (period == 2){
            this.secondScore += addScore;
        }

        setUpdateOption();
    }

    public Map<Integer, SnowGardenSkinData> getSkinList() {
        return skinList;
    }

    public void setSkinList(Map<Integer, SnowGardenSkinData> skinList) {
        this.skinList = skinList;
        setInsertOption();
    }

    public List<Integer> getInvitedIdList() {
        return invitedIdList;
    }

    public void setInvitedIdList(List<Integer> invitedIdList) {
        this.invitedIdList = invitedIdList;
        setUpdateOption();
    }

    public List<SnowGardenCombTriggerData> getCombList() {
        return combList;
    }

    public void setCombList(List<SnowGardenCombTriggerData> combList) {
        this.combList = combList;
        setUpdateOption();
    }

    public void addCombTriggerData(SnowGardenCombTriggerData triggerData){
        this.combList.add(triggerData);
        setUpdateOption();
    }

    public boolean isRecharge() {
        return isRecharge;
    }

    public void setRecharge(boolean recharge) {
        isRecharge = recharge;
        setUpdateOption();
    }

    public int getGuarantee() {
        return guarantee;
    }

    public void setGuarantee(int guarantee) {
        if(this.guarantee != guarantee) {
            this.guarantee = guarantee;
            setUpdateOption();
        }
    }

    public List<Integer> getDice() {
        return dice;
    }

    public void setDice(List<Integer> dice) {
        this.dice = dice;
        setUpdateOption();
    }

    public int getBuildingLevel() {
        int level = 0;
        for (SnowGardenMapData mapData : getIndexData().values()) {
            level += mapData.getLevel();
        }
        return level;
    }

    public int getInvitedNum() {
        return invitedNum;
    }

    public void setInvitedNum(int invitedNum) {
        this.invitedNum = invitedNum;
        setUpdateOption();
    }

    public void addInviteNum(int num){
        this.invitedNum += num;
        setUpdateOption();
    }

    public int getSecondScore() {
        return secondScore;
    }

    public void setSecondScore(int secondScore) {
        this.secondScore = secondScore;
        setUpdateOption();
    }
}
